package com.wn55.hrms.web.controller;


import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Implementation;
import com.wn55.hrms.entity.Need;
import com.wn55.hrms.service.ImplementationService;
import com.wn55.hrms.service.NeedService;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author z
 */
@RestController
@RequestMapping("implementation")
@Api(value = "此接口用于操作培训实施功能")
public class ImplementaionController {

    @Autowired
    ImplementationService implementationService;


    @GetMapping("/implementationList")
    @ApiOperation(value = "分页条件查询培训实施")

    public ResultResponse<PageInfo<Implementation>> list(
            @RequestParam(value = "now",defaultValue = "1") Integer now ,
            @RequestParam(value = "size",defaultValue = "2")Integer size,
            String name){
        ResultResponse<PageInfo<Implementation>> result = null;

        try {
            PageInfo<Implementation> pageInfo =implementationService.implementList(now,size,name);
            result = new ResultResponse<>(200,"查询培训实施成功!",pageInfo);
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"查询培训实施失败!");
        }
        return result ;
    }



    @PutMapping("/modify")
    @ApiOperation(value = "培训实施修改")

    public ResultResponse<Void> modify(@RequestBody Implementation implementation){
        ResultResponse<Void> result = null;

        try {
            implementation.setIsDelete(0);

            implementationService.modify(implementation);
            result = new ResultResponse<>(200,"修改培训实施成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"修改培训实施失败!");
        }
        return result ;
    }



    @PostMapping("/add")
    @ApiOperation(value = "实施添加")

    public ResultResponse<Void> add(@RequestBody Implementation implementation){
        ResultResponse<Void> result = null;


        try {
            implementation.setIsDelete(0);

            implementationService.add(implementation);
            result = new ResultResponse<>(200,"添加培训实施成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"添加培训实施失败!");
        }
        return result ;
    }


    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除实施")

    public ResultResponse<Void> del(@PathVariable("id") int id){
        ResultResponse<Void> result = null;

        try {
            implementationService.removeBykey(id);
            result = new ResultResponse<>(200,"删除培训实施成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"删除培训实施失败!");
        }
        return result ;
    }



}
